package com.itxiuyixiu.homework.security.handler;

import com.alibaba.fastjson.JSONObject;
import com.itxiuyixiu.homework.utils.ReturnUtils.ReturnMessage;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 黄磊
 * @date 2020/4/3
 */
public class ApiAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        response.setStatus(200);
        response.setCharacterEncoding("utf-8");
        response.setHeader("content-type", "application/json;charset=UTF-8");
        response.getWriter().write(JSONObject.toJSONString(ReturnMessage.getSuccessReturn("登录成功")));
    }
}
